<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="教职工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-dict-select-tag type="list" v-model="model.userId" dictCode="sys_user,realname,id,del_flag=0 and user_identity=3" placeholder="请选择教职工" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="考勤类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkType">
              <j-dict-select-tag type="list" v-model="model.checkType" dictCode="check_type" placeholder="请选择考勤类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="考勤时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkTime">
              <j-date :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择考勤时间" v-model="model.checkTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="考勤体温" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkTemperature">
              <!-- <a-input suffix="℃" v-model="model.checkTemperature" type="number" placeholder="请输入考勤体温" /> -->
              <a-input-number v-model="model.checkTemperature" :min="0" :precision="1" :max="45" placeholder="请输入体温" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="考勤照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="photo">
              <j-image-upload :number="imgMaxNumber" isMultiple   v-model="model.checkPicture" ></j-image-upload>
              <div>最多上传 <span style="color: #f5222d;">{{ imgMaxNumber }}</span> 张照片</div>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import dateFormat from '@/components/jeecg/JEasyCron/format-date'

  export default {
    name: 'SkStaffCheckForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        imgMaxNumber:1,
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          userId:[{required: true, message: '请选择教工'}],
          checkType:[{required: true, message: '请选择考勤类型'}],
          checkTime:[{required: true, message: '请输入考勤时间'}]
        },
        url: {
          add: "/management/skStaffCheck/add",
          edit: "/management/skStaffCheck/edit",
          queryById: "/management/skStaffCheck/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.modelDefault.checkTime = dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss');
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>
<style scoped lang="less">
/deep/ .ant-input-number{
  position: relative;
}
/deep/ .ant-input-number::before{
  content: "℃";
  position: absolute;
  top: 0;
  right: 32px;
  height: 32px;
  line-height: 32px;
  color: #999;
  font-size: 14px;
}
</style>